﻿namespace SimpleWebServices.Data
{
    using System;
    using System.Data;
    using SimpleWebServices;
    using Xunit;

    public sealed class DataSetExtensionMethodsFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(typeof(DataSetExtensionMethods).IsStatic());
        }

        [Fact]
        public void op_IsEmpty_DataSet()
        {
            Assert.True(new DataSet().IsEmpty());
        }

        [Fact]
        public void op_IsEmpty_DataSetNull()
        {
            Assert.Throws<ArgumentNullException>(() => (null as DataSet).IsEmpty());
        }

        [Fact]
        public void op_IsEmpty_DataSetWithTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("column", typeof(string));

            DataSet dataset = new DataSet();
            dataset.Tables.Add(table);

            Assert.True(dataset.IsEmpty());
        }

        [Fact]
        public void op_IsEmpty_DataSetWithRow()
        {
            DataTable table = new DataTable();
            table.Columns.Add("column", typeof(string));

            DataRow row = table.NewRow();
            row["column"] = "value";
            table.Rows.Add(row);

            DataSet dataset = new DataSet();
            dataset.Tables.Add(new DataTable());
            dataset.Tables.Add(table);

            Assert.False(dataset.IsEmpty());
        }
    }
}